package factory;

import java.io.FileReader;
import java.util.Properties;

public class PortaFactory {
	private static int porta = 8080;
	
	public static int getPorta(String[] args){			
		Properties p = System.getProperties();
		if(p.getProperty("port") == null){
			if(args.length > 0){
				porta = Integer.parseInt(args[0]);
			}
		}else{
			porta = Integer.parseInt(p.getProperty("port"));
		}
		try(FileReader reader = new FileReader("conf.properties")){
			Properties pr = new Properties();
			pr.load(reader);
			if(pr.getProperty("porta") != null){
				porta = Integer.parseInt(pr.getProperty("porta"));
			}
			
		}catch (Exception e) {
			e.printStackTrace();
		}
		
		return porta;
	}
}
